﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using NavigationBarDemo.Controls;
using NavigationBarDemo.Controls.NavigationBar;

namespace NavigationBarDemo
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();

            InitControl();
        }

        private int _count = 0;
        private NavigationButton _navButton;

        private void InitControl()
        {
            for (int i = 0; i < 10; i++)
            {
                _navButton = new NavigationButton()
                {
                    Text = "信号性质" + ++_count,
                    ImageSource = new BitmapImage(new Uri("/NavigationBarDemo;component/Images/image_01.png", UriKind.RelativeOrAbsolute)),
                    ActiveImageSource = new BitmapImage(new Uri("/NavigationBarDemo;component/Images/image_02.png", UriKind.RelativeOrAbsolute))
                };

                XNavigationBar.AddItem(_navButton);
            }
            XNavigationBar.SelectionChanged += XNavigationBar_SelectionChanged;

            XNavigationBar.SelectedIndex = 0;
        }

        void XNavigationBar_SelectionChanged(object sender, RoutedEventArgs e)
        {
            NavigationButton navBtn = e.OriginalSource as NavigationButton;
            if (navBtn != null)
                Debug.WriteLine(navBtn.Text);
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            _navButton = new NavigationButton()
            {
                Text = "信号性质" + ++_count,
                ImageSource = new BitmapImage(new Uri("/NavigationBarDemo;component/Images/image_01.png", UriKind.RelativeOrAbsolute)),
                ActiveImageSource = new BitmapImage(new Uri("/NavigationBarDemo;component/Images/image_02.png", UriKind.RelativeOrAbsolute))
            };

            XNavigationBar.AddItem(_navButton);
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            XNavigationBar.RemoveItem(XNavigationBar.SelectedItem);
        }

        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            _count = 0;
            XNavigationBar.ClearItems();
        }
    }
}
